package cn.net.mugui.net.pc.panel.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;

import com.mugui.Dui.DTextArea;
import com.mugui.Dui.DVerticalFlowLayout;
import com.mugui.sql.util.StringUtils;

import cn.net.mugui.net.p2p.ServerAttr;

public class ChatMsgView extends JPanel {
	public ChatMsgView() {
		this.setBackground(null);
		this.setLayout(new DVerticalFlowLayout());

		JPanel panel_9 = new JPanel();
		panel_9.setBorder(BorderFactory.createRaisedBevelBorder());
		panel_9.setBackground(Color.LIGHT_GRAY);
		this.add(panel_9);

		JLabel label_3 = new JLabel("用户：");
		label_3.setFont(new Font("宋体", Font.BOLD, 13));
		label_3.setForeground(Color.RED);

		name = new JLabel("未知");
		name.setForeground(new Color(0, 128, 128));

		JLabel label_5 = new JLabel("地址：");
		label_5.setForeground(new Color(0, 0, 255));
		label_5.setFont(new Font("宋体", Font.BOLD, 13));

		address = new JLabel("");
		address.setForeground(new Color(106, 90, 205));
		GroupLayout gl_panel_9 = new GroupLayout(panel_9);
		gl_panel_9.setHorizontalGroup(gl_panel_9.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_9.createSequentialGroup().addGap(5).addComponent(label_3).addGap(5)
						.addComponent(name, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED).addComponent(label_5).addGap(5)
						.addComponent(address, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)));
		gl_panel_9.setVerticalGroup(gl_panel_9.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_9.createSequentialGroup().addGroup(gl_panel_9.createParallelGroup(Alignment.LEADING)
						.addComponent(name, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(address, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(label_3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(label_5, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))));
		panel_9.setLayout(gl_panel_9);

		JPanel panel_11 = new JPanel();
		panel_11.setBackground(null);
		this.add(panel_11);
		panel_11.setLayout(new BorderLayout(0, 0));

		msg_area = new DTextArea();
		msg_area.setForeground(new Color(255, 0, 255));
		msg_area.setFont(new Font("宋体", Font.PLAIN, 13));
		msg_area.setBackground(null);
		msg_area.setEditable(false);
		panel_11.add(msg_area);
	}

	private ServerAttr serverAttr;
	private DTextArea msg_area;
	private JLabel address;
	private JLabel name;

	/**
	 * 绑定消息
	 * 
	 * @author 木鬼
	 * @param self
	 * @param trim
	 * @return
	 */
	public Component bind(ServerAttr self, String trim) {
		this.serverAttr = self;
		address.setText(self.getAddress());
		if (StringUtils.isBlank(self.getName())) {
			name.setText("未知");
		} else
			name.setText(self.getName());
		msg_area.setText(trim);
		return this;
	}

}
